//增

const User = require("../models/user");
// 需要增加的新用户
let newUser = {
    username:"zhangsan",
    password:"123456",
    name:"张三",
    age:18,
    sex:"男",
    tel:123456789,
    mail:"123456789@qq.com"
}

let newUser1 = {
    username:"zhaoliu",
    password:"123456",
    name:"赵六",
    age:38,
    sex:"nv",
    tel:123456789,
    mail:"123456789@qq.com",
    skill:[{skillName:"java",skillTime:"7"},{skillName:"python",skillTime:"3"}]
}
// toSave(newUser);
toCreat(newUser1);



//利用model 的Save方法 添加数据
async function toSave(obj){
    try{
        let saveUser = new User(obj);
        let UserDoc = await saveUser.save();
        console.log(`保存后的数据${UserDoc}`);
    }catch(err){
        console.log(err.message);
    }    
}

//利用model 的creat方法 添加数据

async function toCreat(obj){
    try{
        let creatUser = new User(obj);
        let UserDoc = await User.create(creatUser);
        console.log(`保存后的数据${UserDoc}`);
    }catch(err){
        console.log(err.message);
    }    
}